<template>
	<view class="content">
		<view class="padding ">
			<view class="neirong">
				<view class="flexbetween padding ffffff border">
					<view class="text_x color_ling">真实姓名</view>
					<input class="inputs textright" type="text" placeholder-class="font-size: 30rpx; color: #999999;"
						placeholder="请输入真实姓名" v-model="real_name">
				</view>
				<view class="flexbetween padding ffffff border margin_top">
					<view class="text_x color_ling">身份证号</view>
					<input class="inputs textright" placeholder-class="font-size: 30rpx; color: #999999;" type="number"
						placeholder="请输入身份证号" v-model="id_card">
				</view>
				<!-- 身份证 -->
				<view class="flexbetween margin_top">
					<view class="shefz" @click="uploadImg(1)">
						<image v-if="!id_card_zimage" src="/static/image/my/sfz_zm.png" mode=""></image>
						<image v-if="id_card_zimage" :src="id_card_zimage" mode=""></image>
					</view>
					<view class="shefz" @click="uploadImg(3)">
						<image v-if="!id_card_fimage" src="/static/image/my/sfz_fm.png" mode=""></image>
						<image v-if="id_card_fimage" :src="id_card_fimage" mode=""></image>
					</view>
				</view>
			</view>
			<!-- 固定底部 -->
			<view class="gudingdb ffffff" @click="submit">
				<view class="bigbtn">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				real_name: "",
				id_card: "",
				id_card_zimage: "",
				id_card_fimage: "",
				upImg:[]
			}
		},
		methods: {
			uploadImg(value) {
				let _this = this;
				let upImgs = _this.upImg;
				let num = 6 - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], value)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], value)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, value) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					if (value == 1) {
						_this.id_card_zimage = res.fullurl
					} else {
						_this.id_card_fimage = res.fullurl
					}
				}).catch(err => {});
			},
			submit() {
				let _this = this;
				if (_this.real_name == '') {
					httpRequest.toast('请输入真实姓名！')
					return
				}
				if (_this.id_card == '') {
					httpRequest.toast('请输入身份证号！')
					return
				}
				if (_this.id_card_zimage == '') {
					httpRequest.toast('请上传身份证头像面！')
					return
				}
				if (_this.id_card_fimage == '') {
					httpRequest.toast('请上传身份证国徽面！')
					return
				}
				httpRequest.request('/api/user/realnameRz', 'GET', {
					real_name: _this.real_name,
					id_card: _this.id_card,
					id_card_zimage: _this.id_card_zimage,
					id_card_fimage: _this.id_card_fimage,
				}).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages_my/shenhe"
							})
						}, 500)
					} else {
						httpRequest.toast(res.msg)
					}
					console.log(res);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shanchu {
		width: 13rpx;
		height: 13rpx;
		background-size: 100% 100%;
		//background-image: url('../static/image/my/shanchu.png');
	}

	.shilitu {
		position: relative;
	}

	.shanchubox {
		position: absolute;
		top: 30rpx;
		right: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 39rpx;
		height: 23rpx;
		background: #D0D0D0;
		border-radius: 0px 7rpx 0px 7rpx;
	}

	.shangchuan {
		width: 193rpx;
		height: 193rpx;
		background-size: 100% 100%;
		margin-right: 10rpx;
	}

	.neirong {
		padding-bottom: 200rpx;
	}

	.shefz {
		width: 48%;
		height: 291rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.yyz {
		width: 100%;
		height: 291rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}


	.inputs {
		width: 60%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		text-align: right;
	}

	.zdy {
		font-size: 30rpx;
		width: 100%;
	}

	/deep/.selected-item-active {
		border-bottom: 2px solid #ffc059;
	}
</style>